package com.banggood.upms.config;

import com.banggood.upms.common.plugin.UniversalEnumConverterFactory;
import com.banggood.upms.intercepter.MainInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class UpmsWebAppConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(new UniversalEnumConverterFactory());
    }

    //拦截器链
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MainInterceptor()).addPathPatterns("/**");
    }

    /**
     * 将你保存文件的路径指定一个实际的物理路径，然后访问图片可以通过配置相对路径映射
     * 访问路径如下：http://hostname:port/img/XXX
     * @param registry
     */
    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img*//**").addResourceLocations("d:/image");
    }*/
}
